Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

path-to-prop

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

path-to-prop

Retrieves a property from an object based on a 'path/to.that.prop'

  • 3.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Path to prop 🛤

Total Downloads Latest Stable Version

npm i path-to-prop

Retrieves a property from an object based on a 'path/to.that.prop'

  • Supports paths with both / and . to separate props
  • Safely typed (with TypeScript) - returns unknown

Usage

import { getProp } from 'path-to-prop'

getProp({ nested: { prop: 1 } }, 'nested.prop') // 1

getProp({ nested: { prop: 1 } }, 'nested') // { prop: 1 }

You can use / or . to access nested props:

const obj = {a: {b: {c: {d: {e: 1}}}}}
const path = 'a/b/c.d.e'

getProp(obj, path)
  // returns 1

getProp(obj, 'nonexistent.prop')
  // returns undefined

When you have / or . in your prop names, use an array:

const obj = {'a/b': {'c.d': 1}}

getProp(obj, ['a/b', 'c.d'])
  // returns 1

Keywords

FAQs

Package last updated on 18 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc